#include "led.h"

void led_fun(char *uled)
{
    uint8_t temp = 0x00;
    static uint8_t temp_old = 0xff;

    for (uint8_t i = 0; i < 8;i++)
        temp |= uled[i] << i;

        if(temp != temp_old)
        {
            GPIOC->ODR &= 0x00ff;
            GPIOC->ODR |= ~(temp << 8);

            GPIOD->BSRR |= 0x01 << 2;
            GPIOD->BRR |= 0x01 << 2;

            temp_old = temp;
        }
}

uint8_t uled[8] = {0,0,0,0,0,0,0,0};
uint8_t flag_led = 0;
void led_proc(void)
{
    if(show_mode == 0)
    {
        if(flag_led != time.Seconds)
        {
            uled[0] ^= 1;
            uled[1] = 0;
            uled[2] = 0;
            flag_led = time.Seconds;
        }
        
    }
    else if(show_mode == 1)
    {
        uled[1] = 1;
        uled[0] = 0;
        uled[2] = 0;
    }
    else if(show_mode == 2)
    {
        uled[1] = 0;
        uled[0] = 0;
        uled[2] = 1;
    }
    led_fun(uled);
}

